/**
 * 时间格式化
 * @param {*} date        - 时间数据
 * @param {string} format - 格式
 * @return {string}
 * @example
 * // "yyyy-MM-dd hh:mm:ss.S" -> 2018-11-08 16:27:03.231
 */
 import CryptoJS from 'crypto-js'
 /**
  * 加密（需要先加载lib/aes/aes.min.js文件）
  */
 const AuthTokenKey = 'summitsummitsumm' // AES密钥
 const AuthTokenIv = 'summitsummitsumm' // AES向量
 const encrypt = (data) => {
     const encrypted = CryptoJS.AES.encrypt(data, CryptoJS.enc.Latin1.parse(AuthTokenKey), {
         iv: CryptoJS.enc.Latin1.parse(AuthTokenIv),
         mode: CryptoJS.mode.CBC,
         padding: CryptoJS.pad.ZeroPadding
     })
     return encrypted.toString()
 }
    //防抖
const debounce = (fn, t) => {
        let timer;
        const time = t || 50;
        return function() {
            if (timer) {
                clearTimeout(timer);
            }
            timer = setTimeout(() => {
                timer = null;
                // fn.apply(this, arguments);
                // this[fn]();
            }, time);
        };
    }


export const lib = {
    encrypt,
    debounce,
};

export default {
    install(Vue) {
        Vue.prototype.$lib = lib;
    }
};